function [a,P] = Random(P,S,mode)

% game parameters
global num_players_r;
global num_players_b;

if(P{2}=='r')
    num_players = num_players_r;
    num_opponents = num_players_b;
else
    num_players = num_players_b;
    num_opponents = num_players_r;
end

% select action
if(PlayerInPossession(P,S,mode)) % either Dribble() or PassBall()
    if(rand(1)<=1/(1+num_players))
        [a, P] = Dribble(P);
        SaveMemory(P,false,1,0);
    else
        k = round(rand_num(0.5,num_players+0.5)); % choose a random team-mate to pass to
        [a,P] = PassBall(P,S,mode,k);
        SaveMemory(P,true,1+k,0);
    end
else
    if(TeamInPossession(P,S,mode)) % GetOpen or stand still waiting for a pass(because another teammate has the ball)
        if(rand(1)<=0.5)
            [a,P] = GetOpen(P,S,mode);
            SaveMemory(P,true,2+num_players,0);
        else % stand still = pass to yourself (without having the ball)
            P_num = P{3};
            [a,P] = PassBall(P,S,mode,P_num);
            SaveMemory(P,true, P_num+1, 0);
        end
    elseif(OpponentInPossession(P,S,mode))  % either GoToBall() or BlockPass()
        if(rand(1)<=0.5)
            [a, P] = GoToBall(P,S,mode);
            SaveMemory(P,true,3+num_players,0);
        else
            k = round(rand_num(0.5,num_opponents+0.5)); % choose a random opponent to block
            [a,P] = BlockPass(P,S,mode,k);
            SaveMemory(P,true,3+num_players+k,0);
        end
    else % the ball is free for the taking
        p = rand(1);
        %if(IsClosest(P,S,mode))
        if(p<=0.33)    
            [a,P] = GoToBall(P,S,mode);
            SaveMemory(P,true,3+num_players,0);
        elseif(p <= 0.66)
            [a,P] = GetOpen(P,S,mode);
            SaveMemory(P,true,2+num_players,0);
        else
            k = round(rand_num(1,num_opponents)); % choose a random opponent to block
            [a,P] = BlockPass(P,S,mode,k);
            SaveMemory(P,true,3+num_players+k,0);
        end
    end
end


end